home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Aug 89 / X0074-DrawShapes Example-Aug89 < prev    next >
Encoding:
Text File  |  1989-08-22  |  4.2 KB  |  131 lines  |  [TEXT/GEOL]

  1. Item    4302652                         17-Aug-89        17:52
  2.  
  3. From:   D1282                           Channelmark, Nancy Melone,PRT
  4.  
  5. To:     MACAPP.TECH$                    MACAPP Tech
  6.  
  7. Sub:    DrawShapes Example
  8.  
  9. Gentlepersons,
  10.  
  11. I have only recently begun to program in MacApp, and I have already hit
  12. something I don't quite understand.
  13.  
  14. In the DrawShapes MacApp example shipped with MacApp 2.0B9, in the routine
  15. TShapeDocument.DoMakeViews(), it appears that the value of the field fShapeView
  16. is being used before it is being initialized.  The code looks as follows:
  17.  
  18. PROCEDURE TShapeDocument.DoMakeViews(forPrinting: BOOLEAN);
  19.  
  20.    VAR
  21.        shapeView:  TShapeView;
  22.        palette:TPalette;
  23.        aWindow:TWindow;
  24.        aDocState:  DocState;
  25.        minSize:Point;
  26.        maxSize:Point;
  27.  
  28.    BEGIN
  29.        IF forPrinting THEN
  30.            palette := NIL
  31.        ELSE
  32.            BEGIN
  33.            New(palette);
  34.            FailNIL(palette);
  35.  
  36.            palette.IPalette(SELF);
  37.            fPaletteView := palette;
  38.            END;
  39.  
  40.        New(shapeView);
  41.        FailNIL(shapeView);
  42.        shapeView.IShapeView(SELF, palette, FALSE);
  43.  
  44.    // notice that shapeView has been initialized, but not assigned to
  45.    //   fShapeView
  46.  
  47.        IF NOT forPrinting THEN
  48.            BEGIN
  49.            aWindow := NewPaletteWindow(kShapeWindowRSRCID,
  50.                                     kWantHScrollBar,
  51.                                     kWantVScrollBar,
  52.                                     SELF,
  53.                                        fShapeView,  // NOT a var parameter; it
  54.                                                  // looks like its being used
  55.                                                  // before it's initialized
  56.                                     fPaletteView,
  57.                                     kPaletteWidth,
  58.                                     kLeftPalette);
  59.  
  60.         // if fShapeView is not initialized, this will lead to disaster
  61.            fShapeView.fScroller := fShapeView.GetScroller(TRUE);
  62.  
  63. // etc.
  64.  
  65. The comments following C++ style comment delimiters are my own.  Doesn't this
  66. code look suspicious?  If you poke around a bit, as I did, you'll find that in
  67. the routine TShapeView.IShapeView(), which is called in the code fragment
  68. above, the following code is executed:
  69.  
  70. PROCEDURE TShapeView.IShapeView(itsDocument: TShapeDocument;
  71.                                 itsPalette: TPalette;
  72.                                    forClipboard: BOOLEAN);
  73.  
  74.    VAR
  75.     itsLocation:   VPoint;
  76.        itsSize:VPoint;
  77.        aHandler:   TStdPrintHandler;
  78.        aDocState:  DocState;
  79.        sd: SizeDeterminer;
  80.  
  81.    BEGIN
  82.        fDragging := FALSE;
  83.        fPalette := itsPalette;
  84.        SetVPt(itsSize, kMaxCoord, kMaxCoord);
  85.        IF forClipboard THEN
  86.            sd := sizeVariable
  87.        ELSE
  88.            sd := sizeFillPages;
  89.  
  90.        IView(itsDocument, NIL, gZeroVPt, itsSize, sd, sd);
  91.        fScroller := NIL;
  92.  
  93.        IF itsDocument <> NIL THEN
  94.            itsDocument.fShapeView := SELF;
  95.  
  96. // etc.
  97.  
  98. Notice that in the last little IF statement, the given document's fShapeView
  99. field gets initialized.  Since TShapeView.IShapeView() gets executed before
  100. fShapeView is used in NewPaletteWindow(), everything works.
  101.  
  102. So, my question is one of object-oriented programming style.  In the example as
  103. described above, the document's fShapeView field is initialized not in the
  104. document's initialization code, but rather in the code that initializes the
  105. shape view itself!  This is certainly counter to my intuitiveness.
  106.  
  107. Wouldn't it be more clear to have the TShapeDocument.DoMakeViews() code read:
  108.        New(shapeView);
  109.        FailNIL(shapeView);
  110.        shapeView.IShapeView(SELF, palette, FALSE);
  111.     fShapeView := shapeView;
  112.  
  113. …and to have the TShapeView.IShapeView() code NOT contain the final IF
  114. statement listed above, that assigns SELF to fShapeView?  None of the routines
  115. below the IF statement depend on the value of fShapeView.
  116.  
  117. I am not bringing this up to pick nits.  I am just concerned that this odd code
  118. may be an example of GOOD MacApp code, and that my not understanding this
  119. example means that I am missing some subtle aspect of OOP, Object Pascal, or
  120. MacApp.
  121.  
  122. Thanks for your help!
  123.  
  124.  
  125. James Plamondon
  126. Software Engineer
  127. PowerUp Software
  128. San Mateo, CA  94403
  129. (415) 345-5900 x351
  130.  
  131.